package com.zrsx.searchmodel.controller;


import com.zrsx.searchmodel.common.result.Result;
import com.zrsx.searchmodel.common.entity.CreditInterpretation;
import com.zrsx.searchmodel.common.vo.DimensionVO;
import com.zrsx.searchmodel.common.vo.RankDisplayVO;
import com.zrsx.searchmodel.service.CreditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/credit")
@Slf4j
@Tag(name = "信用分搜索")
public class CreditController {
    @Autowired
    private CreditService creditService;

    @Operation(summary = "获取信用分")
    @GetMapping("/{id}")
    public Result<Integer> getCredit(@PathVariable Integer id){
        Integer credit = creditService.getCredit(id);
        return Result.success(credit);
    }

    @GetMapping("/rank/{id}")
    @Operation(summary = "获取用户信用排名")
    public Result<Long> getRank(@PathVariable Integer id) {
        Long rank = creditService.getRank(id);
        return Result.success(rank);
    }


    @GetMapping("/interpretation/{id}")
    @Operation(summary = "获取信用解读")
    public Result<CreditInterpretation> getCreditInterpretation(@PathVariable Integer id) {
        CreditInterpretation creditInterpretation = creditService.getCreditInterpretation(id);
        return Result.success(creditInterpretation);
    }


    @Operation(summary = "获取某个维度信用分")
    @GetMapping("/{id}/{dimension}")
    public Result<Integer> getCreditDimension(@PathVariable Integer id,@PathVariable String dimension){
        Integer credit = creditService.getCreditDimension(id,dimension);
        return Result.success(credit);
    }

    @Operation(summary = "获取各个维度信用分")
    @GetMapping("/dimensions/{id}")
    public Result<List<DimensionVO>> getCreditDimensions(@PathVariable Integer id){
        List<DimensionVO> credit = creditService.getAllDimensions(id);
        return Result.success(credit);
    }

    @Operation(summary = "获取信用排名前10名用户")
    @GetMapping("/rank")
    public Result<List<RankDisplayVO>> getCreditRank() {
        List<RankDisplayVO> rankList = creditService.getTopCreditRank(10);
        return Result.success(rankList);
    }
}
